package com.meeting.controller.customer;

import com.meeting.dto.OrdersQueryDTO;
import com.meeting.dto.RoomBookDTO;
import com.meeting.entity.Orders;
import com.meeting.service.OrdersService;
import com.meeting.vo.OrdersVO;
import com.meeting.vo.PageResult;
import com.meeting.vo.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/customer/orders")
@Tag(name = "客户会议室订单接口")
@Slf4j
public class CustomerOrdersController {

    @Autowired
    OrdersService ordersService;

    /**
     * 分页查询查看相关订单，可以看有没有什么选择的字段
     * @return
     */
    @GetMapping
    @Operation(summary = "分页条件搜索查询所有订单")
    public Result listAllOrders(OrdersQueryDTO ordersQueryDTO){
        log.info("查询相关订单{}",ordersQueryDTO);
        PageResult<OrdersVO> orders =  ordersService.listAll(ordersQueryDTO);
        return Result.success(orders);
    }

    @PostMapping("/book")
    @Operation(summary = "创建订单")
    public Result createOrders(@RequestBody RoomBookDTO roomBookDTO){
        log.info("创建订单，预定会议室{}",roomBookDTO);
        Orders orders = ordersService.createOrders(roomBookDTO);
        return Result.success(orders);
    }

    @PutMapping("/{id}")
    @Operation(summary = "支付订单")
    public Result payOrders(@PathVariable Integer id){
        log.info("支付订单{}",id);
        ordersService.payOrders(id);
        return Result.success();
    }

    @DeleteMapping("/cancel/{id}")
    @Operation(summary = "取消订单")
    public Result cancelOrders(@PathVariable Integer id){
        log.info("取消订单{}",id);
        ordersService.cancelOrders(id);
        return Result.success();
    }

    @DeleteMapping("/refund/{id}")
    @Operation(summary = "退款")
    public Result refundOrders(@PathVariable Integer id){
        log.info("订单退款{}",id);
        return ordersService.refund(id);
    }



}